home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 52
/
Volume 52 - JOGO DISK .iso
/
Games
/
shopdrop.swf
/
scripts
/
__Packages
/
smashing
/
Point.as
< prev
next >
Wrap
Text File
|
2007-09-27
|
4KB
|
193 lines
class smashing.Point
{
function Point(x, y)
{
this.x = Number(x);
this.y = Number(y);
}
function get length()
{
return Math.sqrt(this.x * this.x + this.y * this.y);
}
function set length(newLength)
{
if(this.__get__length() != 0)
{
var _loc2_ = newLength / this.__get__length();
this.x *= _loc2_;
this.y *= _loc2_;
}
}
function get lengthSqu()
{
return this.x * this.x + this.y * this.y;
}
function copy()
{
return new smashing.Point(this.x,this.y);
}
function addPoint(p)
{
return new smashing.Point(p.x + this.x,p.y + this.y);
}
function subtractPoint(p)
{
return new smashing.Point(this.x - p.x,this.y - p.y);
}
function addScalar(n)
{
return new smashing.Point(this.x + n,this.y + n);
}
function subtractScalar(n)
{
return new smashing.Point(this.x - n,this.y - n);
}
function addPointMe(p)
{
this.x += p.x;
this.y += p.y;
}
function subtractPointMe(p)
{
this.x -= p.x;
this.y -= p.y;
}
function addScalarMe(n)
{
this.x += n;
this.y += n;
}
function subtractScalarMe(n)
{
this.x -= n;
this.y -= n;
}
function multiply(nFactor)
{
var _loc2_ = this.copy();
_loc2_.x *= nFactor;
_loc2_.y *= nFactor;
return _loc2_;
}
function divide(n)
{
var _loc2_ = this.copy();
if(n == 0)
{
_loc2_.x = 0;
_loc2_.y = 0;
return undefined;
}
_loc2_.x /= n;
_loc2_.y /= n;
return _loc2_;
}
function multiplyMe(n)
{
this.x *= n;
this.y *= n;
}
function divideMe(n)
{
this.x /= n;
this.y /= n;
}
function dot(p)
{
return this.x * p.x + this.y * p.y;
}
function cross()
{
return new smashing.Point(this.y,- this.x);
}
function normalize()
{
if(!this.x && !this.y)
{
return undefined;
}
var _loc2_ = this.__get__length();
return new smashing.Point(this.x / _loc2_,this.y / _loc2_);
}
function normalizeMe()
{
if(!this.x && !this.y)
{
return undefined;
}
var _loc2_ = this.__get__length();
this.x /= _loc2_;
this.y /= _loc2_;
}
function reverse()
{
var _loc2_ = new smashing.Point(this.x * -1,this.y * -1);
return _loc2_;
}
function reverseMe()
{
this.x *= -1;
this.y *= -1;
}
function rotateMe(nRad)
{
var _loc2_ = Math.sin(nRad);
var _loc3_ = Math.cos(nRad);
if(_loc2_ > 1 || _loc2_ < -1)
{
}
if(_loc3_ > 1 || _loc3_ < -1)
{
}
this.x = this.x * _loc3_ + this.y * (- _loc2_);
this.y = this.x * _loc2_ + this.y * _loc3_;
}
function rotate(nRad)
{
var _loc2_ = Math.sin(nRad);
var _loc3_ = Math.cos(nRad);
if(_loc2_ > 1 || _loc2_ < -1)
{
}
if(_loc3_ > 1 || _loc3_ < -1)
{
}
return new smashing.Point(this.x * _loc3_ + this.y * (- _loc2_),this.x * _loc2_ + this.y * _loc3_);
}
function rotateSinCos(nSin, nCos)
{
this.x = this.x * nCos + this.y * (- nSin);
this.y = this.x * nSin + this.y * nCos;
}
function findCosine(vOther)
{
var _loc3_ = this.dot(vOther);
var _loc4_ = this.__get__length() * vOther.__get__length();
var _loc2_ = _loc3_ / _loc4_;
return _loc2_;
}
function equals(p)
{
if(this.x == p.x && this.y == p.y)
{
return true;
}
return false;
}
function zero()
{
this.x = 0;
this.y = 0;
}
function distSqu(p)
{
var _loc3_ = p.x - this.x;
var _loc2_ = p.y - this.y;
return _loc3_ * _loc3_ + _loc2_ * _loc2_;
}
function toString()
{
return "Point (" + this.x + "," + this.y + ")";
}
}